<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>DataExtractor: E:/cas/cas.0.7.0/sfw/src/MinConsole/MinConsole.0.8.0/MinConsole/Gaf/Utils/INI/IniReader.cs Source File</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<link href="../../doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.7.2 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul class="tablist">
      <li><a href="../../index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="../../namespaces.html"><span>Packages</span></a></li>
      <li><a href="../../annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="../../files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs2">
    <ul class="tablist">
      <li><a href="../../files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<h1>E:/cas/cas.0.7.0/sfw/src/MinConsole/MinConsole.0.8.0/MinConsole/Gaf/Utils/INI/IniReader.cs</h1>  </div>
</div>
<div class="contents">
<a href="../../d6/d9d/IniReader_8cs.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 ﻿using System;
<a name="l00002"></a>00002 <span class="keyword">using</span> System.Collections.Generic;
<a name="l00003"></a>00003 <span class="keyword">using</span> System.Linq;
<a name="l00004"></a>00004 <span class="keyword">using</span> System.Text;
<a name="l00005"></a>00005 <span class="keyword">using</span> MinConsole.IniParser;
<a name="l00006"></a>00006 <span class="keyword">using</span> System.IO;
<a name="l00007"></a>00007 
<a name="l00008"></a><a class="code" href="../../d5/d17/namespaceGaf_1_1Utils_1_1INI.html">00008</a> <span class="keyword">namespace </span>Gaf.Utils.INI
<a name="l00009"></a>00009 {
<a name="l00010"></a><a class="code" href="../../d1/d2b/classGaf_1_1Utils_1_1INI_1_1IniReader.html">00010</a>     <span class="keyword">class </span><a class="code" href="../../d1/d2b/classGaf_1_1Utils_1_1INI_1_1IniReader.html">IniReader</a>
<a name="l00011"></a>00011     {
<a name="l00012"></a><a class="code" href="../../d1/d2b/classGaf_1_1Utils_1_1INI_1_1IniReader.html#a0ac5ea224db39301902bd916f8643e16">00012</a>         <span class="keyword">static</span> <span class="keywordtype">string</span> strIniFile = MinConsole.Gaf.IO.FileUtility.CreateProcessDefaultIniFile();
<a name="l00013"></a><a class="code" href="../../d1/d2b/classGaf_1_1Utils_1_1INI_1_1IniReader.html#ab2c8bf575e06f971819023256be43837">00013</a>         <span class="keyword">static</span> <span class="keywordtype">string</span> strNewIniFile = <span class="stringliteral">&quot;New&quot;</span> + Environment.GetCommandLineArgs()[0] + <span class="stringliteral">&quot;.ini&quot;</span>; 
<a name="l00014"></a>00014 
<a name="l00015"></a>00015 
<a name="l00016"></a>00016         
<a name="l00017"></a><a class="code" href="../../d1/d2b/classGaf_1_1Utils_1_1INI_1_1IniReader.html#a085a231ce486da0db98cd864428680ba">00017</a>         <span class="keyword">public</span> <span class="keyword">static</span> <span class="keywordtype">void</span> IniFileTests()
<a name="l00018"></a>00018         {
<a name="l00019"></a>00019             <span class="comment">//Create an instance of a ini file parser</span>
<a name="l00020"></a>00020             MinConsole.IniParser.FileIniDataParser parser = <span class="keyword">new</span> MinConsole.IniParser.FileIniDataParser();
<a name="l00021"></a>00021 
<a name="l00022"></a>00022             <span class="keywordflow">if</span> (File.Exists(strNewIniFile))
<a name="l00023"></a>00023                 File.Delete(strNewIniFile);
<a name="l00024"></a>00024 
<a name="l00025"></a>00025             <span class="comment">//Parse the ini file</span>
<a name="l00026"></a>00026             MinConsole.IniParser.IniData parsedData = parser.LoadFile(strIniFile);
<a name="l00027"></a>00027 
<a name="l00028"></a>00028             <span class="comment">//Write down the contents of the ini file to the console</span>
<a name="l00029"></a>00029             Console.WriteLine(<span class="stringliteral">&quot;---- Printing contents of the INI file ----\n&quot;</span>);
<a name="l00030"></a>00030             Console.WriteLine(ElaboratedParsing(parsedData, parser));
<a name="l00031"></a>00031 
<a name="l00032"></a>00032             <span class="comment">//Get concrete data from the ini file</span>
<a name="l00033"></a>00033             Console.WriteLine(<span class="stringliteral">&quot;---- Printing contents concrete data from the INI file ----&quot;</span>);
<a name="l00034"></a>00034             Console.WriteLine(<span class="stringliteral">&quot;setMaxErrors = &quot;</span> + parsedData[<span class="stringliteral">&quot;GeneralConfiguration&quot;</span>][<span class="stringliteral">&quot;setMaxErrors&quot;</span>]);
<a name="l00035"></a>00035             Console.WriteLine();
<a name="l00036"></a>00036 
<a name="l00037"></a>00037             <span class="comment">//Modify the INI contents and save</span>
<a name="l00038"></a>00038             Console.WriteLine();
<a name="l00039"></a>00039             <span class="comment">//Write down the contents of the modified ini file to the console</span>
<a name="l00040"></a>00040             Console.WriteLine(<span class="stringliteral">&quot;---- Printing contents of the new INI file ----\n&quot;</span>);
<a name="l00041"></a>00041             <a class="code" href="../../dd/de3/classMinConsole_1_1IniParser_1_1IniData.html" title="Represents all data from an INI file.">IniData</a> modifiedParsedData = ModifyINIData(parsedData);
<a name="l00042"></a>00042             Console.WriteLine(ElaboratedParsing(modifiedParsedData, parser));
<a name="l00043"></a>00043 
<a name="l00044"></a>00044             <span class="comment">//Save to a file</span>
<a name="l00045"></a>00045             <span class="comment">//parser.SaveFile(strNewIniFile, modifiedParsedData);</span>
<a name="l00046"></a>00046             Console.ReadKey();
<a name="l00047"></a>00047         } <span class="comment">//eof method</span>
<a name="l00048"></a>00048 
<a name="l00049"></a>00049 
<a name="l00050"></a><a class="code" href="../../d1/d2b/classGaf_1_1Utils_1_1INI_1_1IniReader.html#ae1dde1b01a818950f079464c37911155">00050</a>         <span class="keyword">private</span> <span class="keyword">static</span> <span class="keywordtype">string</span> ElaboratedParsing(<a class="code" href="../../dd/de3/classMinConsole_1_1IniParser_1_1IniData.html" title="Represents all data from an INI file.">IniData</a> parsedData, <a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html" title="Represents an INI data parser for streams.">StreamIniDataParser</a> parser)
<a name="l00051"></a>00051         {
<a name="l00052"></a>00052             StringBuilder sb = <span class="keyword">new</span> StringBuilder();
<a name="l00053"></a>00053 
<a name="l00054"></a>00054             <span class="comment">//Process data: print contents of the file into screen</span>
<a name="l00055"></a>00055             <span class="keywordflow">foreach</span> (<a class="code" href="../../da/d5e/classMinConsole_1_1IniParser_1_1SectionData.html" title="Information associated to a section in a INI FileIncludes both the value and the comments associated ...">SectionData</a> sectionData <span class="keywordflow">in</span> parsedData.Sections)
<a name="l00056"></a>00056             {
<a name="l00057"></a>00057                 <span class="comment">//Print comments for current section</span>
<a name="l00058"></a>00058                 <span class="keywordflow">foreach</span> (<span class="keywordtype">string</span> sectionComment <span class="keywordflow">in</span> sectionData.<a class="code" href="../../da/d5e/classMinConsole_1_1IniParser_1_1SectionData.html#a1ea697b805ef5c5b697bfe83e6972f7d" title="Gets or sets the comment list associated to this section.">Comments</a>)
<a name="l00059"></a>00059                     sb.AppendLine(parser.CommentDelimiter + sectionComment);
<a name="l00060"></a>00060 
<a name="l00061"></a>00061                 <span class="comment">//Print section&#39;s name</span>
<a name="l00062"></a>00062                 sb.AppendLine(
<a name="l00063"></a>00063                     parser.SectionDelimiters[0] + sectionData.<a class="code" href="../../da/d5e/classMinConsole_1_1IniParser_1_1SectionData.html#adab8fdbc92f03583cbd7bc609240d010" title="Gets or sets the name of the section.">SectionName</a> + parser.SectionDelimiters[1]);
<a name="l00064"></a>00064 
<a name="l00065"></a>00065                 sb.AppendLine();
<a name="l00066"></a>00066 
<a name="l00067"></a>00067                 <span class="comment">//Print section&#39;s key-value pairs with it&#39;s comments</span>
<a name="l00068"></a>00068                 <span class="keywordflow">foreach</span> (<a class="code" href="../../d7/d40/classMinConsole_1_1IniParser_1_1KeyData.html" title="Information associated to a key from an INI file.Includes both the value and the comments associated ...">KeyData</a> keyData <span class="keywordflow">in</span> sectionData.<a class="code" href="../../da/d5e/classMinConsole_1_1IniParser_1_1SectionData.html#a1b9719c87649991337673af8793d90ee" title="Gets or sets the keys associated to this section.">Keys</a>)
<a name="l00069"></a>00069                 {
<a name="l00070"></a>00070                     <span class="comment">//Print comments for current key</span>
<a name="l00071"></a>00071                     <span class="keywordflow">foreach</span> (<span class="keywordtype">string</span> keyComment <span class="keywordflow">in</span> keyData.<a class="code" href="../../d7/d40/classMinConsole_1_1IniParser_1_1KeyData.html#a1ea697b805ef5c5b697bfe83e6972f7d" title="Gets or sets the comment list associated to this key.">Comments</a>)
<a name="l00072"></a>00072                         sb.AppendLine(parser.CommentDelimiter + keyComment);
<a name="l00073"></a>00073 
<a name="l00074"></a>00074                     <span class="comment">//Print key and value</span>
<a name="l00075"></a>00075                     sb.AppendLine(keyData.<a class="code" href="../../d7/d40/classMinConsole_1_1IniParser_1_1KeyData.html#ad75286a69f558484322dac5297e2ed64" title="Gets or sets the name of the key.">KeyName</a> + <span class="stringliteral">&quot; &quot;</span> + parser.KeyValueDelimiter + <span class="stringliteral">&quot; &quot;</span> + keyData.<a class="code" href="../../d7/d40/classMinConsole_1_1IniParser_1_1KeyData.html#af7b88db799d8f791f785e437bc6099d2" title="Gets or sets the value associated to this key.">Value</a>);
<a name="l00076"></a>00076 
<a name="l00077"></a>00077                     sb.AppendLine();
<a name="l00078"></a>00078                 }
<a name="l00079"></a>00079 
<a name="l00080"></a>00080                 sb.AppendLine();
<a name="l00081"></a>00081             } <span class="comment">//eof foreach </span>
<a name="l00082"></a>00082 
<a name="l00083"></a>00083             <span class="keywordflow">return</span> sb.ToString();
<a name="l00084"></a>00084         } <span class="comment">//eof method </span>
<a name="l00085"></a>00085 
<a name="l00086"></a><a class="code" href="../../d1/d2b/classGaf_1_1Utils_1_1INI_1_1IniReader.html#ac01fd516ae8da0c3d9900c19e9a25ed6">00086</a>         <span class="keyword">private</span> <span class="keyword">static</span> <a class="code" href="../../dd/de3/classMinConsole_1_1IniParser_1_1IniData.html" title="Represents all data from an INI file.">IniData</a> ModifyINIData(<a class="code" href="../../dd/de3/classMinConsole_1_1IniParser_1_1IniData.html" title="Represents all data from an INI file.">IniData</a> modifiedParsedData)
<a name="l00087"></a>00087         {
<a name="l00088"></a>00088             modifiedParsedData[<span class="stringliteral">&quot;GeneralConfiguration&quot;</span>][<span class="stringliteral">&quot;setMaxErrors&quot;</span>] = <span class="stringliteral">&quot;15&quot;</span>;
<a name="l00089"></a>00089             modifiedParsedData.<a class="code" href="../../dd/de3/classMinConsole_1_1IniParser_1_1IniData.html#a23b81f7bb2f67084758e5fb63f2431ad" title="Gets or sets all the SectionData for this IniData instance.">Sections</a>.<a class="code" href="../../d4/dcc/classMinConsole_1_1IniParser_1_1SectionDataCollection.html#ad321519caa7c680485c652a6de4986bd" title="Creates a new section with empty data.">AddSection</a>(<span class="stringliteral">&quot;newSection&quot;</span>);
<a name="l00090"></a>00090             modifiedParsedData.<a class="code" href="../../dd/de3/classMinConsole_1_1IniParser_1_1IniData.html#a23b81f7bb2f67084758e5fb63f2431ad" title="Gets or sets all the SectionData for this IniData instance.">Sections</a>.<a class="code" href="../../d4/dcc/classMinConsole_1_1IniParser_1_1SectionDataCollection.html#a0bc57065ca25c4237925dd5f63478c07" title="Returns the section data from a specify section given its name.">GetSectionData</a>(<span class="stringliteral">&quot;newSection&quot;</span>).<a class="code" href="../../da/d5e/classMinConsole_1_1IniParser_1_1SectionData.html#a1ea697b805ef5c5b697bfe83e6972f7d" title="Gets or sets the comment list associated to this section.">Comments</a>
<a name="l00091"></a>00091                 .Add(<span class="stringliteral">&quot;This is a new comment for the section&quot;</span>);
<a name="l00092"></a>00092             modifiedParsedData.<a class="code" href="../../dd/de3/classMinConsole_1_1IniParser_1_1IniData.html#a23b81f7bb2f67084758e5fb63f2431ad" title="Gets or sets all the SectionData for this IniData instance.">Sections</a>.<a class="code" href="../../d4/dcc/classMinConsole_1_1IniParser_1_1SectionDataCollection.html#a0bc57065ca25c4237925dd5f63478c07" title="Returns the section data from a specify section given its name.">GetSectionData</a>(<span class="stringliteral">&quot;newSection&quot;</span>).<a class="code" href="../../da/d5e/classMinConsole_1_1IniParser_1_1SectionData.html#a1b9719c87649991337673af8793d90ee" title="Gets or sets the keys associated to this section.">Keys</a>.<a class="code" href="../../d3/db1/classMinConsole_1_1IniParser_1_1KeyDataCollection.html#a870965bfda85d2d23853afdadf451a74" title="Adds a new key with the specified name and empty value and comments.">AddKey</a>(<span class="stringliteral">&quot;myNewKey&quot;</span>, <span class="stringliteral">&quot;value&quot;</span>);
<a name="l00093"></a>00093             modifiedParsedData.<a class="code" href="../../dd/de3/classMinConsole_1_1IniParser_1_1IniData.html#a23b81f7bb2f67084758e5fb63f2431ad" title="Gets or sets all the SectionData for this IniData instance.">Sections</a>.<a class="code" href="../../d4/dcc/classMinConsole_1_1IniParser_1_1SectionDataCollection.html#a0bc57065ca25c4237925dd5f63478c07" title="Returns the section data from a specify section given its name.">GetSectionData</a>(<span class="stringliteral">&quot;newSection&quot;</span>).<a class="code" href="../../da/d5e/classMinConsole_1_1IniParser_1_1SectionData.html#a1b9719c87649991337673af8793d90ee" title="Gets or sets the keys associated to this section.">Keys</a>.<a class="code" href="../../d3/db1/classMinConsole_1_1IniParser_1_1KeyDataCollection.html#a32d066a8a88afa76b0980e199dd788b0" title="Retrieves the data for a specified key given its name.">GetKeyData</a>(<span class="stringliteral">&quot;myNewKey&quot;</span>).<a class="code" href="../../d7/d40/classMinConsole_1_1IniParser_1_1KeyData.html#a1ea697b805ef5c5b697bfe83e6972f7d" title="Gets or sets the comment list associated to this key.">Comments</a>
<a name="l00094"></a>00094             .Add(<span class="stringliteral">&quot;new key comment&quot;</span>);
<a name="l00095"></a>00095 
<a name="l00096"></a>00096             <span class="keywordflow">return</span> modifiedParsedData;
<a name="l00097"></a>00097         } <span class="comment">//eof method </span>
<a name="l00098"></a>00098 
<a name="l00099"></a>00099 
<a name="l00100"></a>00100     } <span class="comment">//eof class IniReader</span>
<a name="l00101"></a>00101 } <span class="comment">//eof namespace </span>
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Sat Jan 22 2011 22:24:47 for DataExtractor by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
